local AceOO = AceLibrary("AceOO-2.0")
local L = AceLibrary("AceLocale-2.2"):new("Bidder_Recoil")

local Recoil = AceOO.Class(Bidder_DKP_BaseClass)

--[[
  dkpInfo table:
    cost -- number; the cost of the item
    bidplaced -- bool; true if we placed a bid, else false
    bidmodifier -- number; nil -> no bid, else random modifier for my bid
  cost is filled in and passed from DKPmon
]]

--[[
FillTooltip(dkpinfo, mypoints)
Description:
  Called when an item in the Bidding Window is moused over to add the DKP-system 
  specific information to the GameTooltip for the moused over item
Input:
  dkpinfo -- table;  same table returned from DKPmon:GetItemInfo() plus whatever else the DKP system added to track bidding
  mypoints -- table; This is the points table returned by the "RQP" communications command
Returns:
  Nothing
]]
function Recoil.prototype:FillTooltip(dkpinfo, mypoints)
   GameTooltip:AddLine(" ")
   GameTooltip:AddLine(string.format(L["DKP Cost = %g"], dkpinfo.cost),  1.0, 0.819, 0.0) 
   GameTooltip:AddLine(string.format(L["Your DKP = %g"], mypoints[1]),  1.0, 0.819, 0.0)
end

--[[
GetStatusText(dkpinfo)
Description:
  Return the status line text, for the LootItem button, of the item with the given dkpinfo
Input:
  dkpinfo -- table;  same table returned from DKPmon:GetItemInfo() plus whatever else the DKP system added to track bidding
Returns:
  String -- the text to be displayed; -cannot- be nil
]]
function Recoil.prototype:GetStatusText(dkpinfo)
   if dkpinfo.bidplaced then
      return string.format(L["Bid placed (Roll: %d)"], dkpinfo.bidmodifier)
   end
   return ""
end

--[[
OnLeftClick(dewOptions, itembutton, dkpinfo)
Description:
  Called when the user left clicks on an item in the bidding window
Input:
  dewOptions -- An Ace Options table to use if the DKP system needs to build a menu on a left click
  itembutton -- The LootItem object that made this call.
  dkpinfo -- table; same table returned from DKPmon:GetItemInfo() plus whatever else the DKP system added to track bidding
Returns:
  boolean -- true = display the dewdrop menu, false = don't display it
]]
function Recoil.prototype:OnLeftClick(dewOptions, itembutton, dkpinfo)
   -- A left click toggles whether we're bidding on the item
   if dkpinfo.bidplaced then 
   	dkpinfo.bidplaced = nil 
   else 
   	dkpinfo.bidplaced = true
   	if dkpinfo.bidmodifier == nil then
   		-- Only roll a modifier once, regardless of how many times they bid/remove
   		dkpinfo.bidmodifier = math.floor(random()*100)
   	end
   end
   -- Place the bid, telling DKPmon the modifier and the cost expected to pay.
   Bidder.Comm:SendToDKPmon("PB", { item = itembutton.id, dkp = { bidmodifier = dkpinfo.bidmodifier, cost = dkpinfo.cost } }, Bidder.Looting.lootmaster)
   itembutton:UpdateStatusText()
   return false
end

--[[
OnRightClick(dewOptions, itembutton, dkpinfo)
Description:
  Called when the user right clicks on an item in the bidding window
Input:
  dewOptions -- An Ace Options table to use if the DKP system needs to build a menu on a left click
  itembutton -- The LootItem object that made this call.
  dkpinfo -- table; same table returned from DKPmon:GetItemInfo() plus whatever else the DKP system added to track bidding
Returns:
  boolean -- true = display the dewdrop menu, false = don't display it
]]
function Recoil.prototype:OnRightClick(dewOptions, itembutton, dkpinfo)
   -- Points as currency does nothing on a right click
   return false
end

-- Last, but not least, create a Recoil object and register it to Bidder as a DKP system
local RecoilObj = Recoil:new()
Bidder.DKP:Register(RecoilObj, "Recoil", L["Recoil DKP"])